/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Logic;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author David
 */
public class Tabla implements Serializable{
    
    private String nombre;
    private String owner;
    private ArrayList<Columna> columans;
    private boolean insert;
    private boolean delete;
    private boolean alter;
    private boolean select;
    
    public Tabla(){
        insert=false;
        delete=false;
        alter=false;
        select=false;
        nombre="";
        owner="";
        columans=new ArrayList();
    }

    @Override
    public String toString() {
        String ins = insert?"insert":"";
        String del = delete?"delete":"";
        String alt = alter?"alter":"";
        String sel = select?"select":"";
        
        return "(Table:"+nombre+"["+ins+" "+del+" "+alt+" "+sel+"]/"+columans.toString()+")";
    }
    
    
    public Columna getColumna(Columna obj){
        Iterator ite=columans.iterator();
        while(ite.hasNext()){
            Columna aux=(Columna) ite.next();
            if(aux.equals(obj))
                return aux;
        }
        return null;
    }

    @Override
    public boolean equals(Object obj) {
        return nombre.equals(((Tabla)obj).getNombre());
    }    
    
    
    public Tabla(String nombre,String owner, ArrayList<Columna> columans, boolean insert, boolean delete, boolean alter, boolean select) {
        this.nombre = nombre;
        this.owner = owner;
        this.columans = columans;
        this.insert = insert;
        this.delete = delete;
        this.alter = alter;
        this.select = select;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public ArrayList<Columna> getColumans() {
        return columans;
    }

    public void setColumans(ArrayList<Columna> columans) {
        this.columans = columans;
    }

    public Columna getColumna(String columna){
        Columna aux=null;
        Iterator ite=columans.iterator();
        while(ite.hasNext()){
            aux=(Columna) ite.next();
            if(aux.getNombre().equalsIgnoreCase(columna))
                return aux;
        }
        return null;
    }
    public boolean isInsert() {
        return insert;
    }

    public void setInsert(boolean insert) {
        this.insert = insert;
    }

    public boolean isDelete() {
        return delete;
    }

    public void setDelete(boolean delete) {
        this.delete = delete;
    }

    public boolean isAlter() {
        return alter;
    }

    public void setAlter(boolean alter) {
        this.alter = alter;
    }

    public boolean isSelect() {
        return select;
    }

    public void setSelect(boolean select) {
        this.select = select;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }
    
    
    
}
